# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("orchestration.bzl", "create_single_instance_test", "aosp_artifact")

sh_binary(
    name = "fetch_aosp_artifact",
    srcs = ["fetch_aosp_artifact.sh"],
)

go_library(
    name = "e2etesting",
    srcs = [
        "common.go",
    ],
    deps = [
            "@com_github_google_cloud_android_orchestration//pkg/client",
            "@com_github_docker_docker//api/types",
            "@com_github_docker_docker//api/types/container",
            "@com_github_docker_docker//client",
            "@com_github_docker_go_connections//nat",
    ],
)

create_single_instance_test(
  name="create_fixed_build_id_and_target",
  build_id="11510808",
  build_target="aosp_cf_x86_64_phone-trunk_staging-userdebug",
)

aosp_artifact(
  name = "cvd_host_package",
  build_id = "12266267",
  build_target="aosp_cf_x86_64_phone-trunk_staging-userdebug",
  artifact_name = "cvd-host_package.tar.gz",
  out_name = "cvd-host_package.tar.gz",
)

aosp_artifact(
  name = "images_zip",
  build_id = "12266267",
  build_target="aosp_cf_x86_64_phone-trunk_staging-userdebug",
  artifact_name = "aosp_cf_x86_64_phone-img-12266267.zip",
  out_name = "images.zip",
)

go_test(
    name = "create_local_image",
    srcs = ["createlocalimage_test.go"],
    data = [
      ":images_zip",
      ":cvd_host_package",
      "@images//docker:orchestration_image_tar",
    ],
    deps = [
      ":e2etesting",
      "@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
      "@com_github_google_cloud_android_orchestration//pkg/client",
      "@com_github_google_go_cmp//cmp",
    ],
)

go_test(
    name = "create_from_images_zip",
    srcs = ["createfromimageszip_test.go"],
    data = [
      ":images_zip",
      ":cvd_host_package",
      "@images//docker:orchestration_image_tar",
    ],
    deps = [
      ":e2etesting",
      "@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
      "@com_github_google_cloud_android_orchestration//pkg/client",
      "@com_github_google_go_cmp//cmp",
    ],
)

